#include "pwm.h"
#define PWM_ACCURACY 	100


void pwm_init(u8 freq)
{
	#define PWM0_SET_ADDR			0x86
	u8 buff[4] = {0x5A,0x01,(u8)(PWM_ACCURACY>>8),(u8)PWM_ACCURACY};
	buff[1] = freq;
	sys_write_vp(PWM0_SET_ADDR,buff,2);
	
}

void pwm_set_duty(u16 duty)
{
	#define PWM0_OUT_ADDR			0x92
	if(duty>100)
		duty = 100;
	duty = (u16)((float)duty/100.0f*PWM_ACCURACY+0.5f);
	sys_write_vp(PWM0_OUT_ADDR,(u8 *)&duty,1);

}